<?php
// $Id$

/**
 * @file
 * TODO
 */

function _portals_theme_init($path) {
  $base = array(
    'file' => 'theme.inc',
    'path' => "$path/theme",
  );
  $theme_items = array();
//  $theme_items['portals_cols'] = $base + array(
//   'arguments' => array('data' => NULL),
//  );
  $theme_items['portals_cols'] = $base + array(
    'template' => 'portals_cols',
    'arguments' => array('data_array' => NULL),
  );
  $theme_items['portals_list'] = $base + array(
    'template' => 'portals_list',
    'arguments' => array('data' => NULL),
  );
  $theme_items['portals_view_portals'] = $base + array(
    'template' => 'portals_view_portals',
    'arguments' => array('portals' => NULL),
  );
  return $theme_items;
}

//function theme_portals_cols($input) {
//  return 'output';
//}
function template_preprocess_portals_cols(&$variables) {
  drupal_add_css(drupal_get_path('module', 'portals') ."/theme/portals.css");
  $number_of_cols = count($variables['data_array']);
  $variables['number_of_cols'] = $number_of_cols;
  $variables['cols_width'] = 99 / $number_of_cols;
}

function template_preprocess_portals_list(&$variables) {
  drupal_add_css(drupal_get_path('module', 'portals') ."/theme/portals.css");
  portals_include('images');
  $variables['new_image'] = _portals_get_image('newportal');
  $variables['edit_image'] = _portals_get_image('editportal');
  $variables['child_image'] = _portals_get_image('childportal');
  $variables['remove_image'] = _portals_get_image('removeportal');
  $variables['settings_image'] = _portals_get_image('settingsportal');
  $variables['options'] = array('html' => TRUE);
} 

function template_preprocess_portals_view_portals(&$variables) {
  $rows = array();
  foreach($variables['portals'] as &$item) {
    $rows[$item['layout']['row']][$item['layout']['col']][$item['layout']['pri']][] = $item;
  }
  if (!empty($rows)) {
    foreach($rows as $row => &$cols) {
      foreach($cols as $col => &$pris) {
        ksort($pris);
      }
      ksort($cols);
    }
    ksort($rows);
    $variables['output_data'] = $rows;
  }
  drupal_add_css(drupal_get_path('module', 'portals') ."/theme/portals.css");
} 
